﻿<UserControl x:Class="Infrastructure.WpfClient.Controls.InfMediaControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        
   
        
        <Storyboard x:Key="MediaStoryboardResource" SlipBehavior="Slip">
            <MediaTimeline Storyboard.TargetName="media"  Source="pack://siteoforigin:,,,/Media/Kamelot_TH_making.wmv"></MediaTimeline>
            <StringAnimationUsingKeyFrames Storyboard.TargetName="txtPosition"
                                           Storyboard.TargetProperty="Text" FillBehavior="HoldEnd">
                <DiscreteStringKeyFrame Value="Start Video" KeyTime="0:0:0" />
                <DiscreteStringKeyFrame Value="five seconds" KeyTime="0:0:5.8" />
            </StringAnimationUsingKeyFrames>
        </Storyboard>
        
    </UserControl.Resources>
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="MediaElement.Loaded">
            <EventTrigger.Actions>
                <BeginStoryboard Name="mediaStoryboard" Storyboard="{StaticResource MediaStoryboardResource}">
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
        <EventTrigger  RoutedEvent="ButtonBase.Click"  SourceName="cmdPlay">
            <EventTrigger.Actions>
                <BeginStoryboard Name="MediaStoryboard" Storyboard="{StaticResource MediaStoryboardResource}"/>
            </EventTrigger.Actions>
        </EventTrigger>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="cmdStop">
            <EventTrigger.Actions>
                <StopStoryboard BeginStoryboardName="MediaStoryboard"/>
            </EventTrigger.Actions>
        </EventTrigger>

        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="cmdPause">
            <EventTrigger.Actions>
                <PauseStoryboard BeginStoryboardName="MediaStoryboard"/>
            </EventTrigger.Actions>
        </EventTrigger>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="cmdResume">
            <EventTrigger.Actions>
                <ResumeStoryboard BeginStoryboardName="MediaStoryboard"/>
            </EventTrigger.Actions>
        </EventTrigger>
    </UserControl.Triggers>
    <Grid>
     
        <Grid.RowDefinitions>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="10"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Border Grid.Column="0" Grid.Row="0" BorderThickness="3,3,3,3" BorderBrush="Black">
            <MediaElement    Name="media"  HorizontalAlignment="Stretch" Margin="0,0,0,0" 
                             Stretch="UniformToFill">

            </MediaElement>
        </Border>       

        <Rectangle VerticalAlignment="Center"
                   Width="{Binding ElementName=media, Path=Width}"
                   Height="{Binding ElementName=media, Path=Height}"
                   Stretch="UniformToFill"  
                   Grid.Row="1">
            <Rectangle.Fill>
                <VisualBrush Visual="{Binding ElementName=media}">
                    <VisualBrush.RelativeTransform>
                        <ScaleTransform ScaleY="-1" CenterY="0.5"></ScaleTransform>
                    </VisualBrush.RelativeTransform>
                </VisualBrush>
            </Rectangle.Fill>
            <Rectangle.OpacityMask>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Color="Black" Offset="0"></GradientStop>
                    <GradientStop Color="Transparent" Offset="0.6"></GradientStop>
                </LinearGradientBrush>
            </Rectangle.OpacityMask>
        </Rectangle>
    
        <StackPanel Orientation="Horizontal" Grid.Row="2">
            <TextBlock Text="Position"></TextBlock>
            <TextBlock Name="txtPosition" ></TextBlock>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Grid.Row="3" HorizontalAlignment="Stretch">                     
            <Button Name="cmdPlay" Margin="3,3,3,3">Play</Button>
            <Button Name="cmdStop" Margin="3,3,3,3">Stop</Button>
            <Button Name="cmdPause" Margin="3,3,3,3">Pause</Button>
            <Button Name="cmdResume" Margin="3,3,3,3">Resume</Button>
        </StackPanel> 
    </Grid>
</UserControl>
